package com.webchat.admin.service;

import com.webchat.common.bean.APIPageResponseBean;
import com.webchat.common.bean.APIResponseBean;
import com.webchat.common.bean.APIResponseBeanUtil;
import com.webchat.common.exception.BusinessException;
import com.webchat.domain.vo.request.payment.CreateAppRequestVO;
import com.webchat.domain.vo.response.payment.AppBaseResponseVO;
import com.webchat.domain.vo.response.payment.CreateAppResponseVO;
import com.webchat.rmi.pay.PaymentAppServiceClient;
import com.webchat.rmi.user.AccessApplicationServiceClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AccessApplicationService {


    @Autowired
    private AccessApplicationServiceClient accessApplicationServiceClient;

    /**
     * 支付平台创建应用（接入方）
     *
     * @param createAppRequest
     * @return
     */
    public CreateAppResponseVO createApp(CreateAppRequestVO createAppRequest) {
        APIResponseBean<CreateAppResponseVO> responseBean = accessApplicationServiceClient.createApp(createAppRequest);
        if (APIResponseBeanUtil.isOk(responseBean)) {
            return responseBean.getData();
        }
        throw new BusinessException(responseBean.getMsg());
    }

    /**
     * 发布app
     *
     * @return
     */
    public boolean publishApp(Long appId) {
        APIResponseBean<Boolean> responseBean = accessApplicationServiceClient.publishApp(appId);
        if (APIResponseBeanUtil.isOk(responseBean)) {
            return responseBean.getData();
        }
        throw new BusinessException(responseBean.getMsg());
    }

    /**
     * 删除app
     *
     * @param appId
     * @return
     */
    public boolean deleteApp(Long appId) {
        APIResponseBean<Boolean> responseBean = accessApplicationServiceClient.deleteApp(appId);
        if (APIResponseBeanUtil.isOk(responseBean)) {
            return responseBean.getData();
        }
        throw new BusinessException(responseBean.getMsg());
    }


    /**
     * 应用列表
     *
     * @param keywords
     * @param pageNo
     * @param pageSize
     * @return
     */
    public APIPageResponseBean<AppBaseResponseVO> page(String keywords, Integer pageNo, Integer pageSize) {

        return accessApplicationServiceClient.page(keywords, pageNo, pageSize);
    }

}
